package edu.jmu.transmissionassistant.component

import android.content.Context
import android.os.Environment
import androidx.lifecycle.LifecycleCoroutineScope
import com.yanzhenjie.andserver.annotation.Config
import com.yanzhenjie.andserver.framework.config.WebConfig
import com.yanzhenjie.andserver.framework.website.AssetsWebsite
import com.yanzhenjie.andserver.framework.website.FileBrowser
import edu.jmu.transmissionassistant.App
import java.util.concurrent.TimeUnit


@Config
class AppConfig : WebConfig {

    companion object {
        const val PORT = 8080
        const val TIME_OUT = 5
        const val UPLOAD_PATH = "uploads"
        var mainScope: LifecycleCoroutineScope? = null

        fun scope(): LifecycleCoroutineScope {
            return mainScope!!
        }
    }

    override fun onConfig(context: Context, delegate: WebConfig.Delegate) {
        //静态网页存放位置
        delegate.addWebsite(AssetsWebsite(context, "/web"))
        // 添加一个文件浏览器网站
        delegate.addWebsite(FileBrowser(Environment.getExternalStorageDirectory().path))
    }
}